package com.bw.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.mapper.ShopMapper;
import com.bw.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Controller {
    @Autowired
    ShopService shopService;
    //9）查询订单的总价格，编写正确sql的语句（5分）
    @RequestMapping("/seall")
    public Object seall(String nowData){
        List<Map> seall = shopService.seall(nowData);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");

            jsonObject.put("data", seall.get(0).get("num"));
        return jsonObject;
    }
    //10）查询各货物的销售总额的占比，编写正确sql的语句（5分）
      @RequestMapping("/sege")
    public Object sege(String nowData){
        List<Map> seall = shopService.sege(nowData);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        return jsonObject;
    }
    //11）查询各省份的销售总额，编写正确sql的语句（5分）
    @RequestMapping("/senum")
    public Object senum(String nowData){
        List<Map> seall = shopService.senum(nowData);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", 0);
        jsonObject.put("msg", "");
        JSONObject dataObject = new JSONObject();

        JSONArray jsonArray = new JSONArray();
        System.out.println(seall);

        for (Map map : seall) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name", map.get("name"));
            jsonObject1.put("value",map.get("price"));
            jsonArray.add(jsonObject1);
        }

        jsonObject.put("data", dataObject);
        dataObject.put("mapData",jsonArray);
        return jsonObject;
    }
}
